﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class datebasehelper
    {
        private static string constr = "server=.;database=School;uid=sa;pwd=159357wqw";
        private static string sql = "select * from specialty";

        public static void printUserInfoReader()
        {

            string constr = "server=.;database=School;uid=sa;pwd=159357wqw";
            SqlConnection conn = new SqlConnection(constr);
            string sql = "select * from specialty";
            SqlCommand cmd = new SqlCommand(sql, conn);
            conn.Open();
            var read = cmd.ExecuteReader();
            Console.WriteLine("{0}\t{1}\t{2}", "id", "专业名称", "院系号");
            while (read.Read())

               
            {
                Console.WriteLine("{0}\t{1}\t{2}", read["Id"], read["specialty_Name"], read["department_Id"]);
            }
            conn.Close();


        }


        public static void PrintUserInfoAdaper()
        {


            SqlDataAdapter sqldataAdapter = new SqlDataAdapter(sql, constr);


            DataTable dataTable = new DataTable();

            sqldataAdapter.Fill(dataTable);

            Console.WriteLine();

            Console.WriteLine();

            Console.WriteLine();

            Console.WriteLine();

            Console.WriteLine();

            Console.WriteLine("{0}\t{1}\t{2}", "id", "专业名称", "院系号");

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                Console.WriteLine("{0}\t{1}\t{2}", dataTable.Rows[i]["Id"], dataTable.Rows[i]["specialty_Name"], dataTable.Rows[i]["department_Id"]);

            }
        }
    }
}

